package org.springextensions.actionscript.ioc.factory.xml.preprocessors
{
	import org.springextensions.actionscript.ioc.factory.xml.parser.IXMLObjectDefinitionsPreprocessor;
	import org.springextensions.actionscript.ioc.util.Constants;
	import org.springextensions.actionscript.ioc.util.ResourceConstants;

	public class ResourceDefinitionsPreprocessor implements IXMLObjectDefinitionsPreprocessor
	{
		/**
		 * Parse the context to find the SWFs listed as required.
		 */
		public function preprocess(xml:XML):XML
		{
			xml = convertResourceDefinitions(xml);
			xml = convertResourceGroupDefinitions(xml);
			
			trace(xml);
			return xml;
		}	
		
		private function convertResourceDefinitions(xml:XML):XML {
	      var resources:XMLList = xml[ResourceConstants.RESOURCE_ELEMENT];

	      for each(var resourceNode:XML in resources) {
	        resourceNode.setName(Constants.OBJECT);
	      }
	      return xml;
	    }
	    
	    private function convertResourceGroupDefinitions(xml:XML):XML {
	      var resources:XMLList = xml[ResourceConstants.RESOURCE_GROUP_ELEMENT];

	      for each(var resourceNode:XML in resources) {
	        resourceNode.setName(Constants.OBJECT);
	      }
	      return xml;
	    }
	}
}